package com.itstyle.seckill.topic.ai;

/**
 * @Auther: liuwenxiang
 * @Date: 2020/4/30 21:53
 * @Description:
 */
public class PandC {


    static  Object object =new Object();


    volatile  boolean flag = false;


    static  class A implements Runnable{

        @Override
        public void run() {

            while (true){
                synchronized (object){
                    System.out.println("1"+"我获取到锁了");

                    try {
                        object.wait();

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }


                }
            }
        }
    }


    static  class B implements Runnable{

        @Override
        public void run() {
            while (true){
                synchronized (object){
                    System.out.println("2"+"我获取到锁了");

                    try {
                        object.wait();

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }


                }
            }

        }
    }


    static  class C implements Runnable{

        @Override
        public void run() {
            object.notifyAll();
        }
    }

    public static void main(String[] args) {
        new Thread(new C()).start();
        new Thread(new C()).start();
            new Thread(new C()).start();

    }


    class Goods{
        public final String name;
        public final int price;
        public final int id;

        public Goods(String name, int price, int id){
            this.name = name; /*类型*/
            this.price = price; /*价格*/
            this.id = id; /*商品序列号*/
        }

        @Override
        public String toString(){
            return "name: " + name + ",   price:"+ price + ",   id: " + id;
        }
    }
}
